package com.baizhi.controller;

import com.baizhi.pojo.User;
import com.baizhi.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
//直接返回json
@RestController // 等于 Controller + ResponseBody
//解决跨域问题
@CrossOrigin(origins = "http://localhost:8081")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 分页
     * @param currentPage //当前页
     * @return
     */
    @RequestMapping("/page.do")
    public PageInfo<User> getUsers(@RequestParam(value = "currentPage",defaultValue = "1") int currentPage){
        System.out.println("当前页："+currentPage);
        PageInfo<User> users = userService.getUsers(currentPage, 10);
        return users;
    }

    @RequestMapping("/user.do")
    public User getUser(){
        User user = new User();
        user.setUserName("张三");
        user.setAddress("北京海淀");

        return user;
    }
}
